home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GDK / Base.as next >
Text File  |  2006-11-29  |  5KB  |  186 lines

  1. class GDK.Base extends MovieClip
  2. {
  3.    var previewClip = false;
  4.    var paused = false;
  5.    var width = 100;
  6.    var height = 100;
  7.    var halfWidth = 50;
  8.    var halfHeight = 50;
  9.    var version = "GDK 1,3,80,0";
  10.    var running = false;
  11.    var maxFrameTime = 0.05;
  12.    var lastElapsed = 0.005;
  13.    var maxTimeDifference = 0.005;
  14.    function Base()
  15.    {
  16.       super();
  17.       new GDK.EventSubscriber(this);
  18.       this.worlds = new GDK.Collection();
  19.       if(this.useMask)
  20.       {
  21.          this.setMask(this.attachMovie("Square","mcMask",13421568));
  22.       }
  23.       GDK.Base.root = this;
  24.       this.tabChildren = false;
  25.       this.setSize(Math.round(this._xscale),Math.round(this._yscale));
  26.       this._yscale = this._xscale = 100;
  27.       this.previewClip = this._parent._name == "contents";
  28.       if(!this.previewClip)
  29.       {
  30.          for(var _loc3_ in this)
  31.          {
  32.             if(_loc3_.indexOf("mcDead") != -1)
  33.             {
  34.                this[_loc3_].swapDepths(1048575);
  35.                this[_loc3_].removeMovieClip();
  36.             }
  37.          }
  38.       }
  39.    }
  40.    function setSize(w, h, noEvent)
  41.    {
  42.       if(w == this.width && h == this.height)
  43.       {
  44.          return undefined;
  45.       }
  46.       this.halfWidth = w * 0.5;
  47.       this.halfHeight = h * 0.5;
  48.       if(noEvent)
  49.       {
  50.          this.width = w;
  51.          this.height = h;
  52.       }
  53.       else
  54.       {
  55.          this.sendEvent("Resize",this.width = w,this.height = h,this.width,this.height);
  56.       }
  57.       if(this.useMask)
  58.       {
  59.          this.mcMask._xscale = w;
  60.          this.mcMask._yscale = h;
  61.       }
  62.       if(this.mcDead0)
  63.       {
  64.          this.mcDead0._xscale = w;
  65.          this.mcDead0._yscale = h;
  66.       }
  67.    }
  68.    function start()
  69.    {
  70.       if(this.engineIntervalID)
  71.       {
  72.          return undefined;
  73.       }
  74.       this.lastUpdate = getTimer();
  75.       this.engineIntervalID = setInterval(function(o)
  76.       {
  77.          o.update();
  78.       }
  79.       ,0,this);
  80.       this.onStart();
  81.       this.sendEvent("Start");
  82.       this.running = true;
  83.       this.update();
  84.    }
  85.    function pause()
  86.    {
  87.       this.paused = true;
  88.       this.onPause();
  89.       this.sendEvent("Pause");
  90.       this.update();
  91.    }
  92.    function resume()
  93.    {
  94.       this.paused = false;
  95.       this.onResume();
  96.       this.sendEvent("Resume");
  97.       this.update();
  98.    }
  99.    function stop()
  100.    {
  101.       this.running = false;
  102.       clearInterval(this.engineIntervalID);
  103.       delete this.engineIntervalID;
  104.       this.onStop();
  105.       this.sendEvent("Stop");
  106.    }
  107.    function update()
  108.    {
  109.       if(this.paused)
  110.       {
  111.          this.lastUpdate = getTimer();
  112.          return undefined;
  113.       }
  114.       var _loc2_ = Math.min(this.maxFrameTime,(this.lastUpdate - (this.lastUpdate = getTimer())) * -0.001);
  115.       _loc2_ = this.lastElapsed - Math.max(- this.maxTimeDifference,Math.min(this.maxTimeDifference,this.lastElapsed - _loc2_));
  116.       this.activeWorld.update(_loc2_);
  117.       this.activeWorld.render(_loc2_);
  118.       this.onUpdate();
  119.       this.sendEvent("Update",this.lastElapsed = _loc2_);
  120.    }
  121.    function getWorld(name)
  122.    {
  123.       var _loc2_ = this.worlds.length;
  124.       while((_loc2_ = _loc2_ - 1) > -1)
  125.       {
  126.          if(this.worlds[_loc2_].name == name)
  127.          {
  128.             return this.worlds[_loc2_];
  129.          }
  130.       }
  131.       return null;
  132.    }
  133.    function addWorld(worldObj)
  134.    {
  135.       if(!this.worlds.addMember(worldObj))
  136.       {
  137.          return undefined;
  138.       }
  139.       worldObj.displayNode = this;
  140.       worldObj.engine = this;
  141.    }
  142.    function removeWorld(worldObj)
  143.    {
  144.       var _loc2_ = this.worlds.length;
  145.       while((_loc2_ = _loc2_ - 1) > -1)
  146.       {
  147.          if(this.worlds[_loc2_] == worldObj)
  148.          {
  149.             this.worlds.splice(_loc2_,1);
  150.          }
  151.       }
  152.       delete this.worlds[worldObj.name];
  153.       worldObj.removeFromScene();
  154.    }
  155.    function removeAllWorlds()
  156.    {
  157.       this.activeWorld.removeFromScene();
  158.       this.activeWorld = null;
  159.       var _loc2_ = this.worlds.length;
  160.       while((_loc2_ = _loc2_ - 1) > -1)
  161.       {
  162.          this.worlds[_loc2_].removeFromScene();
  163.       }
  164.       this.worlds = new GDK.Collection();
  165.    }
  166.    function setActiveWorld(worldObj)
  167.    {
  168.       if(this.activeWorld == worldObj)
  169.       {
  170.          return undefined;
  171.       }
  172.       this.activeWorld.removeFromScene();
  173.       this.activeWorld = worldObj;
  174.       worldObj.addToScene();
  175.       worldObj.update(0.0001);
  176.       this.onWorldChanged();
  177.       this.sendEvent("WorldChanged");
  178.    }
  179.    function onUnload()
  180.    {
  181.       this.stop();
  182.       this.sendEvent("Unload");
  183.       this.setActiveWorld(null);
  184.    }
  185. }
  186.